﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using MVVM_CAD.Model;
using MVVM_CAD.Common;
using System.Collections.ObjectModel;

namespace MVVM_CAD.Strategy
{
    public class DeleteToolStrategy : StrategyBase
    {
        public DeleteToolStrategy(IFigure figure) : base(figure)
        {
        }

        public override IFigure PerformMouseLeftClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            var list = (ObservableCollection<IFigure>) figures;
            foreach (var figure in list)
                try
                {
                    if (figure.PointsCollection.Single(p => p.X == point.X && p.Y == point.Y) != null)
                    {
                        figure.PointsCollection.ForEach(p => p.Color = Colors.White);
                        FigureDrawer.DrawFigure(canvas, figure);
                        Figure = figure;
                    }
                }
                catch (InvalidOperationException)
                { }
            list.Remove(Figure);
            Figure.DrawStatus = DrawStatus.Incompleted;
            return Figure;
        }

        public override IFigure PerformMouseLeftClicUpEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseRightClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            return Figure;
        }

        public override IFigure PerformMouseMoveEvent(IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseMoveEvent(DrawingCanvas Canvas, CustomPoint point)
        {
            throw new NotImplementedException();
        }
    }
}
